package com.data.util;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

/**
 * 软件信息处理工具类
 */
public class SoftwareMassageUtils {

    /**
     * 根据软件信息的集合，处理返回的软件信息的格式
     *
     * @param list
     * @param request
     * @return
     */
    public static Map<String, Object> getSoftwareMassageUtils(List<?> list, HttpServletRequest request) {

        String[] value = {"id", "name", "contents", "menu", "size", "version", "star", "state", "type", "down", "md5", "packageName", "content", "vcontent", "ctime"};
        //获取组装的URL
        String[] url = getDownload(request, null);
        Map<String, Object> map = JsonUtils.detailListToMapUtils(list, url, value);
        return map;

    }

    /**
     * 自定义来转换数据
     *
     * @param list
     * @param request
     * @param urls
     * @param value
     * @return
     */
    public static Map<String, Object> getSoftwareMassageUtils(List<?> list, HttpServletRequest request, String urls, String... value) {
        //获取组装的URL
        String[] url = getDownload(request, urls);
        Map<String, Object> map = JsonUtils.detailListToMapUtils(list, url, value);
        return map;

    }

    /**
     * 处理一些URL
     *
     * @param request
     * @return
     */
    public static String[] getDownload(HttpServletRequest request, String defaultUrL) {
        String rootUrl = JsonUtils.getBasePath(request);
        String iconUrl = defaultUrL;
        if (defaultUrL == null)
            iconUrl = rootUrl + "/indexClient/client/softwareIcon?type=minImage&id=";
        String downloadUrl = rootUrl + "/indexClient/client/downloadsApk?md5=";
        String[] url = {iconUrl, downloadUrl};
        return url;
    }


}
